package com.granada.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author ai
 * @date 2021/4/28
 */
@Component
public class SubstUtils {
    /*
        小程序上传图片路径
     */
    private static String uploadFolderWin;

    public static String getUploadFolderWin(){
        return uploadFolderWin;
    }
    @Value("${file.uploadFolderWin}")
    public void setUploadFolderWin(String uploadFolderWin){
        SubstUtils.uploadFolderWin = uploadFolderWin;
    }
    private static String uploadFolderMac;

    public static String getUploadFolderMac(){
        return uploadFolderMac;
    }
    @Value("${file.uploadFolderMac}")
    public void setUploadFolderMac(String uploadFolderMac){
        SubstUtils.uploadFolderMac = uploadFolderMac;
    }

    private static String uploadFolderLinux;

    public static String getUploadFolderLinux(){
        return uploadFolderLinux;
    }
    @Value("${file.uploadFolderLinux}")
    public void setUploadFolderLinux(String uploadFolderLinux){
        SubstUtils.uploadFolderLinux = uploadFolderLinux;
    }

    private static String domainName;

    public static String getDomainName(){
        return domainName;
    }
    @Value("${domainName}")
    public void setDomainName(String domainName){
        SubstUtils.domainName = domainName;
    }



    public static String ApiImagePath(String str){
//        String uploadFolderWin = environment.getProperty("file.uploadFolderWin");
//        String uploadFolderLinux = environment.getProperty("file.uploadFolderLinux");
//        String uploadFolderMac = environment.getProperty("file.uploadFolderMac");
        String replace =null;
        //判断是什么系统
        String os = System.getProperty("os.name");
        if(os.toLowerCase().startsWith("win")) {
            replace = str.replace("/temp/", SubstUtils.uploadFolderWin);
        }else if(os.toLowerCase().startsWith("mac")){
            replace = str.replace("/temp/", SubstUtils.uploadFolderMac);
        }else {
            replace = str.replace("/temp/", SubstUtils.uploadFolderLinux);
        }
        return replace;
    }

    /*
        小程序返回路径给前台
     */
    public static String DownloadImagePath(String str){
        String staticAccessPath = "/temp/";
        String replace =null;

        //判断是什么系统
        if (str!=null && !str.equals("")){
            String os = System.getProperty("os.name");
            if(os.toLowerCase().startsWith("win")) {
                replace = str.replace(SubstUtils.uploadFolderWin, staticAccessPath);
            }else if(os.toLowerCase().startsWith("mac")){
                replace = str.replace(SubstUtils.uploadFolderMac, staticAccessPath);
            }else {
                replace = str.replace(SubstUtils.uploadFolderLinux, staticAccessPath);
            }
        }else {
            replace="";
        }

        return replace;
    }


    public static void main(String[] args) {
        String sql2 =" update payorder set " +
                "orderStatus ="+"'"+ 1+"'"+","
                +" payOrderNo = "+"'"+ 1+"'"
                +" where outTradeNo= "+"'"+1+"'";
        System.out.println("ssql："+sql2);
    }
}
